package mvp.com.bbc.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import mvp.com.bbc.R;
import mvp.com.bbc.ui.witget.IndexControl;
import mvp.com.bbc.ui.witget.MyIndexView;

/**
 * Created by Administrator on 2017/9/29.
 */

public class ShopFragment extends Fragment {

    private View mInflate;
    private MyIndexView mIndexView;
    private TextView tvLetter;
    private String letters;
    private ListView lv_contactsList;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mInflate = inflater.inflate(R.layout.fragment_shop, container, false);
        return mInflate;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mIndexView = (MyIndexView) mInflate.findViewById(R.id.liv_letters);
        tvLetter = (TextView) mInflate.findViewById(R.id.tv_hint);
        lv_contactsList = (ListView) mInflate.findViewById(R.id.lv_contactsList);
        lv_contactsList.setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_expandable_list_item_1, getData()));
        Map<String, Integer> letterMap = new HashMap<>();
        letterMap.put("A", 0);
        letterMap.put("B", 3);
        letterMap.put("C", 7);
        letterMap.put("F", 10);
        letterMap.put("I", 13);
        letterMap.put("K", 16);
        letterMap.put("L", 19);
        letterMap.put("M", 20);
        letterMap.put("N", 22);
        letterMap.put("S", 23);
        letterMap.put("T", 25);
        letterMap.put("X", 28);
        letterMap.put("X", 40);
        new IndexControl(lv_contactsList, mIndexView, tvLetter, letterMap);
    }

    private List<String> getData() {
        List<String> data = new ArrayList<>();
        data.add("abc");
        data.add("aabc");
        data.add("aabc");
        data.add("babc");
        data.add("b");
        data.add("bc");
        data.add("tabc");
        data.add("tabc");
        data.add("xabc");
        data.add("xabc");
        data.add("xabc");
        data.add("zabc");
        data.add("xyabc");
        data.add("yabc");
        return data;
    }
}
